#!/usr/bin/python
Import ('env')

# TODO: src_env.Append (CCFLAGS = user_options_dict['SDL_CFLAGS'])

sources = env.Glob('*.c')

if env['BF_SPLIT_SRC']:
	numobj = len(sources) 	 
	maxobj = 30 	 

	numlibs = numobj / maxobj 	 
	if (numobj % maxobj): 	 
		numlibs = numlibs + 1 	 
	subsources = [] 	 
	 
	if (env['OURPLATFORM'] == 'win32-mingw'): 	 
		for i in range(numlibs - 1): 	 
			subsources.append(sources[i*maxobj:(i+1)*maxobj]) 	 
		subsources.append(sources[(numlibs-1)*maxobj:])

incs = ' #/intern/guardedalloc #/intern/memutil'
incs += ' ../blenlib ../makesdna ../blenkernel'
incs += ' ../include #/intern/bmfont ../imbuf ../render/extern/include'
incs += ' #/intern/bsp/extern ../radiosity/extern/include'
incs += ' #/intern/decimation/extern ../blenloader'
incs += ' ../../kernel/gen_system #/intern/SoundSystem ../readstreamglue ../nodes'
incs += ' #/intern/elbeem/extern'
incs += ' #/intern/ghost #/intern/opennl/extern'
incs += ' ../gpu #extern/glew/include'

incs += ' ' + env['BF_OPENGL_INC']

defs = []

if env['WITH_BF_PYTHON']:
	incs += ' ../python ' + env['BF_PYTHON_INC']
	if env['BF_DEBUG']:
		defs.append('_DEBUG')
else:
	defs.append('DISABLE_PYTHON')


if env['BF_TWEAK_MODE']:
	defs.append('TWEAK_MODE')

if not env['WITH_BF_YAFRAY']:
	defs.append('DISABLE_YAFRAY')

if env['WITH_BF_INTERNATIONAL']:
	incs += ' ../ftfont'
	defs.append('INTERNATIONAL')
	defs.append('FTGL_STATIC_LIBRARY')

if env['WITH_BF_OPENEXR']:
	defs.append('WITH_OPENEXR')

if env['WITH_BF_OPENJPEG']:
	defs.append('WITH_OPENJPEG')

if env['WITH_BF_DDS']:
	defs.append('WITH_DDS')

if env['WITH_BF_QUICKTIME']:
	incs += ' ' + env['BF_QUICKTIME_INC']
	defs.append('WITH_QUICKTIME')

if env['WITH_BF_ICONV']:
	incs += ' ../quicktime'
	incs += ' ' + env['BF_ICONV_INC']
	defs.append('WITH_ICONV')

if env['WITH_BF_GAMEENGINE']:
	defs.append('GAMEBLENDER=1')
	if env['WITH_BF_SOLID']:
		defs.append('USE_SUMO_SOLID')
	
if env['WITH_BF_FFMPEG']:
	defs.append('WITH_FFMPEG')
	incs += ' ' + env['BF_FFMPEG_INC']

if env['WITH_BF_OGG']:
	defs.append('WITH_OGG')

if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross'):
	incs += ' ' + env['BF_PTHREADS_INC']

if env['WITH_BF_VERSE']:
	defs.append('WITH_VERSE')
	incs += ' ' + env['BF_VERSE_INCLUDE']

# TODO buildinfo
if env['BF_BUILDINFO']:
	defs.append('NAN_BUILDINFO')

if env['BF_NO_ELBEEM']:
	defs.append('DISABLE_ELBEEM')

if env['WITH_BF_SDL']:
	incs += ' ' + env['BF_SDL_INC']
else:
	defs.append('DISABLE_SDL')

if env['WITH_BF_BULLET']:
	defs.append('WITH_BULLET')

if env['BF_SPLIT_SRC'] and (env['OURPLATFORM'] == 'win32-mingw'): 	 
	for i in range(numlibs): 	 
		env.BlenderLib ( libname = 'src%d' % (i), sources = subsources[i], includes = Split(incs), defines = defs, libtype=['core', 'intern'], priority = [5, 25] ) 	 
else:
	env.BlenderLib ( libname = 'src', sources = sources, includes = Split(incs), defines = defs, libtype=['core', 'intern'], priority = [5, 25] )
